<template>
  <div class="test-wrapper">
    <div class="test-grid">
      <div class="column-box">
        <div class="column-header">
          <div class="column-title">
            <img src="@/assets/common/icon-col-1.png" class="icon" />
            <div class="title">精密光栅单色仪3D模型</div>
          </div>
          <div class="option-box">
            <div class="opt-btn" @click="hooks.useHandlePlay">
              <img src="@/assets/common/icon-play.png" class="icon" />
              <span>播放</span>
            </div>
            <div class="opt-btn" @click="hooks.useHandleReset">
              <img src="@/assets/common/icon-replay.png" class="icon" />
              <span>重置</span>
            </div>
          </div>
        </div>
        <div class="column-body">
          <div class="iframe-box">
            <iframe
              :src="iframeUrlNew"
              ref="iframeRef"
              class="iframe"
              @load="sendChangeStatus"
            ></iframe>
          </div>
        </div>
      </div>
      <div class="column-box">
        <div class="column-header">
          <div class="column-title">
            <img src="@/assets/common/icon-col-2.png" class="icon" />
            <div class="title">精密光栅单色仪3D模型</div>
          </div>
          <div class="more-box"></div>
        </div>
        <div class="column-body">
          <control></control>
        </div>
      </div>
    </div>
    <div class="test-column">
      <div class="column-box">
        <div class="column-header">
          <div class="column-title">
            <img src="@/assets/common/icon-col-3.png" class="icon" />
            <div class="title">精密光栅单色仪3D模型</div>
            <div class="tag">v2.1.0</div>
          </div>
          <div class="tab-col">
            <div
              class="col-item"
              :class="{ cur: curTab == index }"
              v-for="(item, index) in tabList"
              :key="index"
              @click="handleCurrentChange(index)"
            >
              {{ item }}
            </div>
          </div>
        </div>
        <div class="column-body">
          <div class="tab-box">
            <tab1 v-if="curTab == 0"></tab1>
            <tab2 v-if="curTab == 1"></tab2>
            <tab3 v-if="curTab == 2"></tab3>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref, computed, onMounted, onUnmounted } from "vue";
import { useRouter } from "vue-router";
import { iframeUrl } from "@/utils/iframe";
import control from "@/components/standard/model/control.vue";
import tab1 from "@/components/standard/model/tab1.vue";
import tab2 from "@/components/standard/model/tab2.vue";
import tab3 from "@/components/standard/model/tab3.vue";
import * as hooks from "@/hooks/useTest2Hooks";
const iframeRef = hooks.useIframeRef();
const router = useRouter();
const query: any = computed(() => router.currentRoute.value.query);
const iframeUrlNew = computed(() => `${iframeUrl}&expid=${query.value.code}`);
const tabList = ref(["控制面板", "测量", "分析"]);
const curTab = ref(0);
const handleCurrentChange = (index: number) => {
  curTab.value = index;
};
//3diframe
//iframe加载完成发送消息给3d页面，open状态
const sendChangeStatus = () => {
  if (iframeRef.value?.contentWindow) {
    const datas = {
      type: "changeStatus",
      data: "open",
    };
    iframeRef.value.contentWindow.postMessage(datas, "*");
  }
};
//监听3d传过来的消息
const handleMessage = async (e:any) => {
  console.log("接收iframe的消息：", e.data);
};
onMounted(() => {
  window.addEventListener("message", handleMessage);
});
onUnmounted(() => {
  window.removeEventListener("message", handleMessage);
});
</script>
<style lang="less" scoped>
.test-wrapper {
  width: 1200px;
  margin: 12px auto 0px;
  .test-column {
    display: flex;
    align-items: center;
    justify-content: center;
    .column-box {
      width: 1200px;
      height: 645px;
      background: #ffffff;
      border-radius: 8px;
    }
  }
  .test-grid {
    display: flex;
    margin-bottom: 12px;
    justify-content: space-between;
    .column-box {
      width: 848px;
      height: 400px;
      background: #ffffff;
      border-radius: 8px;
      &:last-child {
        width: 340px;
        height: 400px;
        background: #ffffff;
        border-radius: 8px;
      }
    }
  }
  .column-box {
    padding: 0 16px;
    .column-header {
      display: flex;
      height: 60px;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px solid #e6ebf1;
      .column-title {
        display: flex;
        align-items: center;
        .icon {
          width: 20px;
          height: 20px;
          margin-right: 8px;
        }
        .title {
          font-family: PingFangSC, PingFang SC;
          font-weight: 500;
          font-size: 16px;
          color: #262626;
          line-height: 22px;
          text-align: left;
          font-style: normal;
        }
        .tag {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 12px;
          color: #595959;
          line-height: 18px;
          font-style: normal;
          padding: 0 12px;
          margin-left: 6px;
          height: 18px;
          background: #f1f1f1;
          border-radius: 4px;
        }
      }
      .tab-col {
        width: 270px;
        height: 32px;
        background: #f2f3f5;
        border-radius: 4px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: relative;
        &::before {
          position: absolute;
          content: "";
          width: 1px;
          height: 12px;
          background: #bec4ca;
          left: 90px;
          top: 10px;
        }
        &::after {
          position: absolute;
          content: "";
          width: 1px;
          height: 12px;
          background: #bec4ca;
          left: 180px;
          top: 10px;
        }
        .col-item {
          width: 90px;
          height: 32px;
          display: flex;
          align-items: center;
          justify-content: center;
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 12px;
          color: #595959;
          position: relative;
          z-index: 1;
          cursor: pointer;
          &.cur {
            background: #2776ff;
            color: #fff;
            border-radius: 4px;
          }
        }
      }
      .option-box {
        display: flex;
        align-items: center;
        .opt-btn {
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
          width: 72px;
          height: 32px;
          background: #ffffff;
          border-radius: 4px;
          border: 1px solid #e6ebf1;
          margin-left: 12px;
          .icon {
            width: 20px;
            height: 20px;
            margin-right: 4px;
          }
          span {
            font-family: PingFangSC, PingFang SC;
            font-weight: 400;
            font-size: 14px;
            color: #262626;
            line-height: 20px;
            text-align: left;
            font-style: normal;
          }
        }
      }
    }
    .column-body {
      .iframe-box {
        width: 816px;
        height: 324px;
        background: #f2f3f5;
        .iframe {
          width: 100%;
          height: 100%;
          box-sizing: border-box;
          border: 0;
        }
      }
    }
  }
}
</style>
